﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsTamUngNhaCungCap
    {
        private string mDienGiaiAnh = "";
        private string mDienGiaiViet = "";
        private string mKhoa = "";
        private string mKhoaDoiTuongCo = "";
        private string mKhoaLoaiTien = "";
        private string mKhoaNhaCungCap = "";
        private string mKhoaPhuongThucTamUng = "";
        private string mKhoaTaiKhoanCo = "";
        private string mNgayChungTu = "";
        private string mNguoiNhan = "";
        private string mNguonNhap = "";
        private string mSoChungTu = "";
        private double mSoTienChiPhi = 0.0;
        private double mSoTienChiPhiNT = 0.0;
        private double mSoTienTamUng = 0.0;
        private double mSoTienTamUngNT = 0.0;
        private double mSoTienTra = 0.0;
        private double mSoTienTraNT = 0.0;
        private double mTyGia = 0.0;
        private double mTyGiaThue = 0.0;

        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM GL_TamUngNhaCungCapChiTietTmp WHERE KhoaTamUng = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
            commandText = "DELETE FROM GL_TamUngNhaCungCapChiTietChiPhiTmp WHERE KhoaTamUng = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool DelData(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, pKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Int64, ParameterDirection.Output, 0);
                bool flag2 = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_TamUngNhaCungCapDel", commandParameters) > 0;
                flag = flag2;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetList(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "select TUKH.KHOAPHUONGTHUCTAMUNG, PTTU.TENVIET PHUONGTHUCTAMUNG, TUKH.SOCHUNGTU, dbo.char2date(TUKH.NGAYCHUNGTU) NGAYCHUNGTU , DMKH.MA, DMKH.TENVIET TENNHACUNGCAP, TUKH.NGUOINHAN, TUKH.KHOATAIKHOANCO, DMTK.SOTAIKHOAN, DMTK.TENVIET TENTAIKHOAN, TUKH.KHOADOITUONGCO, DMDT.TENVIET TENDOITUONG, TUKH.KHOALOAITIEN, DMLT.TENVIET TENLOAITIEN,  TUKH.TYGIA, TUKH.NGUONNHAP , TUKH.TYGIATHUE, TUKH.SOTIENTAMUNG, TUKH.SOTIENTAMUNGNT, TUKH.SOTIENTRA, TUKH.SOTIENTRANT, TUKH.SOTIENCHIPHI, TUKH.SOTIENCHIPHINT, TUKH.DIENGIAIVIET, TUKH.DIENGIAIANH, TUKH.KHOA from GL_TamUngNhaCungCap TUKH left join DM_PHUONGTHUCTAMUNG PTTU on TUKH.KHOAPHUONGTHUCTAMUNG = PTTU.KHOA left join DM_DOITUONG DMKH on TUKH.KHOANHACUNGCAP = DMKH.KHOA\tleft join DM_TAIKHOAN DMTK on TUKH.KHOATAIKHOANCO = DMTK.KHOA\tleft join DM_DOITUONG DMDT on TUKH.KHOADOITUONGCO = DMDT.KHOA\tleft join DM_LOAITIEN DMLT on TUKH.KHOALOAITIEN = DMLT.MA " + str2;
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM GL_TamUngNhaCungCap WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaPhuongThucTamUng = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhaCungCap = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mNguoiNhan = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoanCo = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuongCo = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetDecimal));
                    this.mNguonNhap = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mTyGiaThue = Conversions.ToDouble(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienTamUng = Conversions.ToDouble(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienTamUngNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienTra = Conversions.ToDouble(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienTraNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienChiPhi = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoTienChiPhiNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetDecimal));
                    this.mDienGiaiViet = Conversions.ToString(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetString));
                    this.mDienGiaiAnh = Conversions.ToString(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x16];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaPhuongThucTamUng", DbType.Int64, ParameterDirection.Input, this.mKhoaPhuongThucTamUng);
                commandParameters[2] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, this.mSoChungTu);
                commandParameters[3] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, this.mNgayChungTu);
                commandParameters[4] = DBHelper.createParameter("@KhoaNhaCungCap", DbType.Int64, ParameterDirection.Input, this.mKhoaNhaCungCap);
                commandParameters[5] = DBHelper.createParameter("@NguoiNhan", DbType.Int64, ParameterDirection.Input, this.mNguoiNhan);
                commandParameters[6] = DBHelper.createParameter("@KhoaTaiKhoanCo", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiKhoanCo);
                commandParameters[7] = DBHelper.createParameter("@KhoaDoiTuongCo", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuongCo);
                commandParameters[8] = DBHelper.createParameter("@KhoaLoaiTien", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiTien);
                commandParameters[9] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[10] = DBHelper.createParameter("@NguonNhap", DbType.Int64, ParameterDirection.Input, this.mNguonNhap);
                commandParameters[11] = DBHelper.createParameter("@TyGiaThue", DbType.Date, ParameterDirection.Input, this.mTyGiaThue);
                commandParameters[12] = DBHelper.createParameter("@SoTienTamUng", DbType.Date, ParameterDirection.Input, this.mSoTienTamUng);
                commandParameters[13] = DBHelper.createParameter("@SoTienTamUngNT", DbType.Date, ParameterDirection.Input, this.mSoTienTamUngNT);
                commandParameters[14] = DBHelper.createParameter("@SoTienTra", DbType.Date, ParameterDirection.Input, this.mSoTienTra);
                commandParameters[15] = DBHelper.createParameter("@SoTienTraNT", DbType.Date, ParameterDirection.Input, this.mSoTienTraNT);
                commandParameters[0x10] = DBHelper.createParameter("@SoTienChiPhi", DbType.Date, ParameterDirection.Input, this.mSoTienChiPhi);
                commandParameters[0x11] = DBHelper.createParameter("@SoTienChiPhiNT", DbType.Date, ParameterDirection.Input, this.mSoTienChiPhiNT);
                commandParameters[0x12] = DBHelper.createParameter("@DienGiaiViet", DbType.Int64, ParameterDirection.Input, this.mDienGiaiViet);
                commandParameters[0x13] = DBHelper.createParameter("@DienGiaiAnh", DbType.Int64, ParameterDirection.Input, this.mDienGiaiAnh);
                commandParameters[20] = DBHelper.createParameter("@pError", DbType.Int64, ParameterDirection.Output, 0);
                if (DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_TamUngNhaCungCap", commandParameters) > 0)
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string DienGiaiAnh
        {
            get
            {
                return this.mDienGiaiAnh;
            }
            set
            {
                this.mDienGiaiAnh = value;
            }
        }

        public string DienGiaiViet
        {
            get
            {
                return this.mDienGiaiViet;
            }
            set
            {
                this.mDienGiaiViet = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaDoiTuongCo
        {
            get
            {
                return this.mKhoaDoiTuongCo;
            }
            set
            {
                this.mKhoaDoiTuongCo = value;
            }
        }

        public string KhoaLoaiTien
        {
            get
            {
                return this.mKhoaLoaiTien;
            }
            set
            {
                this.mKhoaLoaiTien = value;
            }
        }

        public string KhoaNhaCungCap
        {
            get
            {
                return this.mKhoaNhaCungCap;
            }
            set
            {
                this.mKhoaNhaCungCap = value;
            }
        }

        public string KhoaPhuongThucTamUng
        {
            get
            {
                return this.mKhoaPhuongThucTamUng;
            }
            set
            {
                this.mKhoaPhuongThucTamUng = value;
            }
        }

        public string KhoaTaiKhoanCo
        {
            get
            {
                return this.mKhoaTaiKhoanCo;
            }
            set
            {
                this.mKhoaTaiKhoanCo = value;
            }
        }

        public string NgayChungTu
        {
            get
            {
                return this.mNgayChungTu;
            }
            set
            {
                this.mNgayChungTu = value;
            }
        }

        public string NguoiNhan
        {
            get
            {
                return this.mNguoiNhan;
            }
            set
            {
                this.mNguoiNhan = value;
            }
        }

        public string NguonNhap
        {
            get
            {
                return this.mNguonNhap;
            }
            set
            {
                this.mNguonNhap = value;
            }
        }

        public string SoChungTu
        {
            get
            {
                return this.mSoChungTu;
            }
            set
            {
                this.mSoChungTu = value;
            }
        }

        public double SoTienChiPhi
        {
            get
            {
                return this.mSoTienChiPhi;
            }
            set
            {
                this.mSoTienChiPhi = value;
            }
        }

        public double SoTienChiPhiNT
        {
            get
            {
                return this.mSoTienChiPhiNT;
            }
            set
            {
                this.mSoTienChiPhiNT = value;
            }
        }

        public double SoTienTamUng
        {
            get
            {
                return this.mSoTienTamUng;
            }
            set
            {
                this.mSoTienTamUng = value;
            }
        }

        public double SoTienTamUngNT
        {
            get
            {
                return this.mSoTienTamUngNT;
            }
            set
            {
                this.mSoTienTamUngNT = value;
            }
        }

        public double SoTienTra
        {
            get
            {
                return this.mSoTienTra;
            }
            set
            {
                this.mSoTienTra = value;
            }
        }

        public double SoTienTraNT
        {
            get
            {
                return this.mSoTienTraNT;
            }
            set
            {
                this.mSoTienTraNT = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }

        public double TyGiaThue
        {
            get
            {
                return this.mTyGiaThue;
            }
            set
            {
                this.mTyGiaThue = value;
            }
        }
    }
}

